#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/octave/debian/defs.make

DEB_COMPRESS_EXCLUDE := .py
R_LIBRARY_DIR := /usr/lib/R/site-library

makebuilddir:: debian/stamp-nonfree
debian/stamp-nonfree:
	@if [ -e src/classifier/svm/SVM_light.cpp ]; then \
	  echo "Do you really want to build a nonfree version? (y/N): "; \
	  read answer; \
	  if [ "$$answer" != y ]; then \
	    exit 1; \
	  fi; \
	fi
	touch $@

# python
configure/shogun-python-modular:: debian/stamp-configure-python-modular
debian/stamp-configure-python-modular:
	cp -a src build-python-modular
	cd build-python-modular && ./configure --prefix=/usr --interface=python-modular
	touch $@

build/shogun-python-modular:: debian/stamp-build-python-modular
debian/stamp-build-python-modular:
	$(MAKE) -C build-python-modular
	touch $@

install/shogun-python-modular:: debian/stamp-install-python-modular
debian/stamp-install-python-modular:
	$(MAKE) -C build-python-modular install DESTDIR=$(CURDIR)/debian/shogun-python-modular
	dh_pycentral -pshogun-python-modular
	touch $@

# python
configure/shogun-python:: debian/stamp-configure-python
debian/stamp-configure-python:
	cp -a src build-python
	cd build-python && ./configure --prefix=/usr --interface=python
	touch $@

build/shogun-python:: debian/stamp-build-python
debian/stamp-build-python:
	$(MAKE) -C build-python
	dh_pycentral -pshogun-python
	touch $@

install/shogun-python:: debian/stamp-install-python
debian/stamp-install-python:
	$(MAKE) -C build-python install DESTDIR=$(CURDIR)/debian/shogun-python
	touch $@

# readline
configure/shogun-readline:: debian/stamp-configure-readline
debian/stamp-configure-readline:
	cp -a src build-readline
	cd build-readline && ./configure --prefix=/usr --interface=cmdline
	touch $@

build/shogun-readline:: debian/stamp-build-readline
debian/stamp-build-readline:
	$(MAKE) -C build-readline
	touch $@

install/shogun-readline:: debian/stamp-install-readline
debian/stamp-install-readline:
	$(MAKE) -C build-readline install DESTDIR=$(CURDIR)/debian/shogun-readline
	touch $@

# octave
configure/shogun-octave:: debian/stamp-configure-octave
debian/stamp-configure-octave:
	cp -a src build-octave
	cd build-octave && ./configure --prefix=/usr --interface=octave
	touch $@

build/shogun-octave:: debian/stamp-build-octave
debian/stamp-build-octave:
	$(MAKE) -C build-octave
	touch $@

install/shogun-octave:: debian/stamp-install-octave
debian/stamp-install-octave:
	dh_install -pshogun-octave build-octave/sg.oct $(OCTDIR)
	octave-depends
	touch $@

# r
install/shogun-r:: debian/stamp-install-r
debian/stamp-install-r:
	make -C R sg/src
	find R/sg -name COPYING -o -name 'LICENSE*' | xargs rm
	R CMD INSTALL -l $(CURDIR)/debian/shogun-r$(R_LIBRARY_DIR) R/sg
	touch $@

clean::
	$(RM) -r build-* debian/stamp-*
debian/stamp-nonfree:

